package com.tt.fashionWebSite.controller;

import com.tt.fashionWebSite.dto.*;
import com.tt.fashionWebSite.service.Ad_MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@Controller
public class Ad_MemberController {
    @Autowired
    private Ad_MemberService ad_memberService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerMember", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> registerMember(HttpServletRequest request, @RequestBody ThongTinThanhVienDto memberDto) {
        return new JsonResponseDto<Integer>(ad_memberService.registerMember(memberDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerMemberEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<ThongTinThanhVienDto> registerMemberEdit(HttpServletRequest request, @RequestBody ThongTinThanhVienDto memberDto) {
        return new JsonResponseDto<ThongTinThanhVienDto>(ad_memberService.registerMemberEdit(memberDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getMemberInfor", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<ThongTinThanhVienDto>> getMemberInfor(HttpServletRequest request) {
        return new JsonResponseDto<List<ThongTinThanhVienDto>>(ad_memberService.getMemberInfor(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toRegisterMemberPage/{maTV}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toPageProductDetail(HttpServletRequest request, @PathVariable String maTV, Map<String, Object> map) throws ParseException {
        map.put("maTV", maTV);
        return new ModelAndView("admin/ad-member-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/editRegisterMember", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<ThongTinThanhVienDto> getMemberInfoEdit(HttpServletRequest request, @RequestBody ThongTinThanhVienDto memberDto) {
        return new JsonResponseDto<ThongTinThanhVienDto>(ad_memberService.getMemberInfoEdit(memberDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/deleteRegisterMember", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<List<ThongTinThanhVienDto>> getMemberInfoDelete(HttpServletRequest request, @RequestBody List<ThongTinThanhVienDto> lstMemberDto) {
        return new JsonResponseDto<List<ThongTinThanhVienDto>>(ad_memberService.memberInfoDelete(lstMemberDto), JsonResponseCode.SUCCESS);
    }

}
